<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>推广登录页面</title>
    <script th:src="@{/assets/js/jquery-min.js}"></script>
    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/bootstrap.min.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/fonts/line-icons.css}">

    <link rel="stylesheet" type="text/css"th:href="@{/assets/css/main.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/responsive.css}">

    <script>
        var flag = false;
        var flag2 = false;
        $(function () {
            $("#passwd").blur(function(){
                var reg = /^.{6,}$/;
                var passwd = $("#passwd").val();
                if(!reg.test(passwd)){
                    $("#passwdTiShi").text("密码至少六位");
                    flag2=false;
                }else{
                    $("#passwdTiShi").text("");
                    flag2 =true;
                }
                if(flag2 == true){
                    $("#btn").removeAttr("disabled");
                }
            });
        });

        function login() {
            var phone = $("#nameOrPhone").val();
            var passwd = $("#passwd").val();
            if (phone == null || phone === "" || phone === undefined) {
                $("#phoneTiShi").text("请输入手机号或用户名");
                flag = false;
            }else {
                flag = true;
            }
            if (passwd == null || passwd === "") {
                $("#passwdTiShi").text("请输入密码");
                flag2 = false;
            }else {
                flag2 = true;
            }
            if(flag === true&&flag2 === true){
                var phoneTishi = $("#phoneTiShi");
                $.ajax({
                    url:"/admin/user/login",
                    dataType:"json",
                    type:"post",
                    data:{"nameOrPhone":$("#nameOrPhone").val(),
                        "passwd":$("#passwd").val()},
                    success:function(data){
                        if(data.isSuccess == "true"){
                            window.open("/com/index","_self");
                        }else {
                            phoneTishi.show();
                            phoneTishi.html(data.message);
                        }
                    },
                    error:function(){
                        alert("运行异常");
                    }
                });
            }
        }
    </script>

</head>
<body>
<div class="wrapper-page">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-lg-5 col-md-12 col-xs-12">
                <div class="card">
                    <div class="card-header border-bottom text-center">
                        <h4 class="card-title">登录</h4>
                    </div>
                    <div class="card-body">
                        <form class="form-horizontal m-t-20">
                            <div class="form-group">
                                <div style="color:red;height: 24px;" id="phoneTiShi" ></div>
                                <input class="form-control" type="text" required="" placeholder="用户名或手机号" id="nameOrPhone">
                            </div>
                            <div class="form-group">
                                <div style="color:red;height: 24px;" id="passwdTiShi" ></div>
                                <input class="form-control" type="password" required="" placeholder="密码" id="passwd">
                            </div>
                            <div class="form-group">
                                <div class="custom-control custom-checkbox">
                                    <input type="checkbox" class="custom-control-input" id="customCheck1">
                                </div>
                            </div>
                            <div class="form-group text-center m-t-20">
                                <button class="btn btn-common btn-block" type="button" onclick="login()">立即登录</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="preloader">
    <div class="loader" id="loader-1"></div>
</div>


<script th:src="@{/assets/js/jquery-min.js}"></script>
<script th:src="@{/assets/js/popper.min.js}"></script>
<script th:src="@{/assets/js/bootstrap.min.js}"></script>
<script th:src="@{/assets/js/jquery.app.js}"></script>
<script th:src="@{/assets/js/main.js}"></script>
</body>
</html>